package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblCTDTNhomMHTuChon;
import com.lb.jwitter.service.TblCTDTNhomMHTuChonService;
import com.lb.jwitter.service.TblCTDTKhoiNganh;
import com.lb.jwitter.service.TblCTDTKhoiNganhService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblCTDTNhomMHTuChonUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private String ma; 
    public void setMa(String ma) {
       this.ma = ma;
 }

    public String getMa() {
       return ma;
 }

    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
 }

    public String getTen() {
       return ten;
 }

    private double soTinChi; 
    public void setSoTinChi(double soTinChi) {
       this.soTinChi = soTinChi;
 }

    public double getSoTinChi() {
       return soTinChi;
 }

    private int khoiNganhId; 
    public void setKhoiNganhId(int khoiNganhId) {
       this.khoiNganhId = khoiNganhId;
 }

    public int getKhoiNganhId() {
       return khoiNganhId;
 }

    private String hocKy; 
    public void setHocKy(String hocKy) {
       this.hocKy = hocKy;
 }

    public String getHocKy() {
       return hocKy;
 }

    private TblCTDTNhomMHTuChon tblCTDTNhomMHTuChon; 
    public void setTblCTDTNhomMHTuChon (TblCTDTNhomMHTuChon tblCTDTNhomMHTuChon) {
        this.tblCTDTNhomMHTuChon = tblCTDTNhomMHTuChon;
 }

    private Collection<TblCTDTNhomMHTuChon> tblCTDTNhomMHTuChons; 
    public void setTblCTDTNhomMHTuChons(Collection<TblCTDTNhomMHTuChon> tblCTDTNhomMHTuChons) {
        this.tblCTDTNhomMHTuChons = tblCTDTNhomMHTuChons; 
      } 

    private TblCTDTNhomMHTuChonService tblCTDTNhomMHTuChonService; 

    private TblCTDTKhoiNganhService tblCTDTKhoiNganhService; 

	private int preUpdate(Message msg, TblCTDTNhomMHTuChon obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblCTDTNhomMHTuChon obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_CTDT_NhomMHTuChon", "sua")){ 
        return "noprivilege"; 
    }
        tblCTDTNhomMHTuChonService = (TblCTDTNhomMHTuChonService) context.getBean("tbl_CTDT_NhomMHTuChonClient"); 
        tblCTDTKhoiNganhService = (TblCTDTKhoiNganhService) context.getBean("tbl_CTDT_KhoiNganhClient"); 

        msg = new Message(); 
        tblCTDTNhomMHTuChon = tblCTDTNhomMHTuChonService.gettblCTDTNhomMHTuChon(new Long(id)); 
        tblCTDTNhomMHTuChon.setMa(ma); 
        tblCTDTNhomMHTuChon.setTen(ten); 
        tblCTDTNhomMHTuChon.setSoTinChi(soTinChi); 
        tblCTDTNhomMHTuChon.setKhoiNganhId(tblCTDTKhoiNganhService.gettblCTDTKhoiNganh(new Long(khoiNganhId))); 
       
        preUpdate(msg,tblCTDTNhomMHTuChon); 
       if (msg.isPreMessage_b()) 
       { 
           tblCTDTNhomMHTuChonService.updatetblCTDTNhomMHTuChon(tblCTDTNhomMHTuChon); 
           postUpdate(msg, tblCTDTNhomMHTuChon); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_CTDT_NhomMHTuChon Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
